package cn.sw.file.config.monitor;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.context.event.ApplicationReadyEvent;
import org.springframework.context.event.EventListener;
import org.springframework.core.env.Environment;
import org.springframework.stereotype.Component;

/**
 * @Description: Nacos 配置中心监听器
 * @Author: 张众森
 * @Date: 2025/5/10
 */
@Component
public class NacosConfigChecker {

    @Autowired
    private Environment environment;

    @EventListener
    public void checkConfigLoaded(ApplicationReadyEvent event) {
        String appName = environment.getProperty("spring.application.name");
        String someKey = environment.getProperty("your.config.key"); // 替换为你在 Nacos 中定义的 key

        System.out.println("\n--------------- Nacos 配置加载状态 ---------------\n");
        System.out.println("\n应用名称: " + appName+"\n");
        if (someKey != null) {
            System.out.println("\n配置项 your.config.key = " + someKey+"\n");
        } else {
            System.err.println("⚠️ 配置项 your.config.key 未找到，可能未正确加载！");
        }
//        System.out.println("\n--------------- Nacos 配置中心连接成功 ---------------");
//        System.out.println("--------------------------------------------------\n");
    }
}
